package com.lyf.baoxian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lyf.baoxian.R;
import com.lyf.baoxian.bean.SearchCustomer;
import com.lyf.baoxian.bean.TestTC;

import java.util.List;

/**
 * Created by 刘亚飞 on 2017/1/8.
 */

public class SearchAdapter extends BaseAdapter {
    private List<SearchCustomer> datas;
    private Context context;

    public SearchAdapter(Context context) {
        this.context = context;
    }

    public void setDatas(List<SearchCustomer> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.title_item_search,null);
            viewHolder = new ViewHolder();
            viewHolder.date = (TextView) view.findViewById(R.id.date);
            viewHolder.goods = (TextView) view.findViewById(R.id.goods);
            viewHolder.person = (TextView) view.findViewById(R.id.dbr);
            viewHolder.price = (TextView) view.findViewById(R.id.yjbf);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }

        SearchCustomer customer = datas.get(i);
        viewHolder.date.setText(customer.getDate()+"");
        viewHolder.goods.setText(customer.getGoods()+"");
        viewHolder.person.setText(customer.getPerson()+"");
        viewHolder.price.setText(customer.getPrice() + "");
        return view;
    }

    class ViewHolder{
        TextView date;
        TextView goods;
        TextView person;
        TextView price;
    }
}
